package com.hrt.manage.order.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hrt.bean.OrderDetail;
import com.hrt.bean.StockDetail;
import com.hrt.manage.order.dao.OrderDetailDao;
import com.hrt.manage.order.service.OrderDetailService;

@Transactional
@Service
public class OrderDetailServiceImpl implements OrderDetailService {
	@Autowired
	private OrderDetailDao orderDetailDao;

	@Override
	public Long totalCount() {
		return orderDetailDao.totalCount();
	}

	@Override
	public void deleteById(Long[] ids) throws Exception {
		List<OrderDetail> delResult = orderDetailDao.getByIds(ids);
		for (OrderDetail gi : delResult) {
			gi.setIsdelete(new Integer(1));
			orderDetailDao.updateEntity(gi);
		}

	}

	@Override
	public void saveOrderDetail(OrderDetail orderDetail) throws Exception {
		orderDetailDao.saveEntity(orderDetail);

	}

	@Override
	public List queryByPage(int pageIndex, int pageSize) {
		return orderDetailDao.queryByPage(pageIndex, pageSize);
	}

	@Override
	public OrderDetail getOrderDetailByid(Long orderDetailId) {
		return orderDetailDao.getById(orderDetailId);
	}

	@Override
	public void updateOrderDetail(OrderDetail orderDetail) {
		orderDetailDao.updateEntity(orderDetail);

	}

	/*
	 * 根据订单ID查找订单详情实体
	 */
	@Override
	public List<OrderDetail> getOrderDetailByOrderId(Long orderId) {
		return orderDetailDao.queryDetailByOrderId(orderId);
	}

	/*
	 * 根据id删除订单详情
	 * 
	 */
	@Override
	public boolean delItemById(Long itemId) {
		OrderDetail item = orderDetailDao.getById(itemId);
		if (item != null) {
			item.setIsdelete(new Integer(1));
			orderDetailDao.updateEntity(item);
			return true;
		}
		return false;
	}

	@Override
	public List queryByPage(String sql, int pageIndex, int pageSize) {
		return orderDetailDao.queryByPage(sql, pageIndex, pageSize);
	}

}
